/* 
 * Copyright [2018] [Alex/libo(liboware@gmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.apidoc.handler;

import java.util.LinkedList;
import java.util.List;

import com.hyts.apidoc.bean.ScanBaseObject;
import com.hyts.apidoc.bean.ScanResultObject;
import com.hyts.apidoc.javadoc.JavaDocSupport;
import com.hyts.apidoc.model.ApiDoc;
import com.hyts.apidoc.parser.JavaDocApiParser;
import com.hyts.apidoc.scanner.SourceScanner;
import com.hyts.apidoc.utility.StringUtils;
import static com.hyts.apidoc.servlet.ApiDocServlet.setApiDocList;

/** 
 * @author LiBo/Alex
 * @version V1.0 
 */
public class TemplateInitHandler {
    
    /**  
     * @param apiDocPackageName
     * @exception
     */ 
    public static void init(String apiDocPackageName) {
        if(StringUtils.isNotEmpty(apiDocPackageName)) {
            ScanBaseObject scanBaseObject = new ScanBaseObject();
            scanBaseObject.packages = new String[] {apiDocPackageName};
            ScanResultObject obj = new SourceScanner(true).scan(scanBaseObject);
            List<String> file = obj.scanResultFile;
            List<Class<?>> classFile = obj.scanResultClass;
            JavaDocSupport.buildJavaDocParam(file);
            setApiDocList(JavaDocApiParser.getApiDocList());
            //补充说明将为完成的数据进行补充说明功能主要补充为两点：class名称、package名称
            List<ApiDoc> dataApidocList = new LinkedList<>();
            List<ApiDoc> nullClassList  = TemplateDataHandler.getClassNameNull();
            List<ApiDoc> notNullClassList = TemplateDataHandler.getPackageNotNull();
            TemplateDataHandler.injectClassName(nullClassList);
            TemplateDataHandler.injectPackageName(nullClassList, classFile);
            TemplateDataHandler.injectPackageName(notNullClassList, classFile);
            dataApidocList.addAll(nullClassList);
            dataApidocList.addAll(notNullClassList);
            setApiDocList(dataApidocList);
        }
    }
    
}
